﻿<%@ Page validateRequest="false" Language="C#" AutoEventWireup="true" CodeBehind="add_test_detail.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Certificate.add_test_detail" %>

<%@ Import Namespace="DataAccess" %>
<%@ Import Namespace="System.Linq" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <%
        int id = int.Parse(Request.Form["id"]);
        int thutu = int.Parse(Request.Form["thutu"]);
        string name = Request.Form["name"];
        string file = Request.Form["file"];
        string pa1 = Request.Form["pa1"];
        string pa2 = Request.Form["pa2"];
        string pa3 = Request.Form["pa3"];
        string pa4 = Request.Form["pa4"];
        int type = int.Parse(Request.Form["type"]);
        int confirm = int.Parse(Request.Form["confirm"]);

        string[] pa = new string[10];
        int get_confirm = 0;

        string[] split = new string[name.Split(' ').Length];
        string edited = "";
        split = name.Split(' ');
        for (int i = 0; i <= name.Split(' ').Length - 1; i++)
        {
            if (split[i] == "/xd/")
                edited += "</br>";
            else
                edited += split[i];
            if (i < name.Split(' ').Length - 1)
                edited += " ";
        }
        name = edited;

        if (file == "")
            new TblTestDetailController().Insert(id, name,type, "", 0, int.Parse(Session["admin_id"].ToString()), true, "");
        else
        {
            string[] temp = new string[file.Split('\\').Length];
            temp = file.Split('\\');
            string upload = temp[file.Split('\\').Length - 1];
            string temp2 = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + Session["admin_id"].ToString();
            upload = temp2 + upload;
            new TblTestDetailController().Insert(id, name,type, upload, 0, int.Parse(Session["admin_id"].ToString()), true, "");
        }


        var get_td = new TblTestDetailController().FetchAll().Where(x => x.TestId == id).Where(x => x.TestDetailQuestion == name).Last();

        pa[1] = pa1;
        pa[2] = pa2;
        pa[3] = pa3;
        pa[4] = pa4;

        for (int i = 1; i <= 4; i++)
        {
            new TblQuestionController().Insert(get_td.TestDetailId, pa[i]);
            if (i == confirm)
            {
                var get_ques = new TblQuestionController().FetchAll().Where(x => x.QuestionName == pa[i]).Last();
                get_confirm = get_ques.QuestionId;
            }
        }

        new TblTestDetailController().Update(get_td.TestDetailId, get_td.TestId, get_td.TestDetailQuestion,get_td.TestDetailType, get_td.TestDetailUrl, get_confirm, get_td.TestDetailTeacher, get_td.TestDetailActive, get_td.TestDetailNote);
    %>
     
</body>
</html>
